// pages/userCenter/moneyBox/moneyBox.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    page:1,
    count: 10,
    money: "",
    recruitList: [],
  },
  getRecruit() {
    var that = this;
    wx.showLoading({
      title: '加载中...',
    })
  },
  
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    wx.showLoading({
      title: '加载中...',
    })

    wx.request({
      url: app.d.severUrl + 'profit_list',
      method: 'GET',
      data: {
        page: that.data.page,
        token: wx.getStorageSync("token")
      },
      success: res => {
        wx.hideLoading();
        if (res.data.code == 0) {
          var content = that.data.recruitList.concat(res.data.data);
          that.setData({
            recruitList: content,
            money:res.data.money
          })

        } else {
          wx.showToast({
            icon: 'none',
            title: res.data.msg
          })
        }
      },
      fail: error => {
        wx.showToast({
          icon: 'none',
          title: "网络错误，请稍后重试"
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this;

    if (that.data.page * that.data.count > that.data.recruitList.length && that.data.recruitList.length > 0) {
      wx.showToast({
        title: '已加载全部数据',
      })
    } else if (that.data.recruitList.length > 0) {
      that.data.page = that.data.page + 1;
      that.getRecruit();
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})